# -*- coding: utf-8 -*-

"""
Created on Fri Jun  8 18:43:24 2018

@author: Administrator
"""
#%%
import os
import glob
import shutil

#%%
class Regular2dpabi(object):
  dpabi_str = 'dpabi_'
  t1_str = 'T1'
  bold_str = 'BOLD'
  star = '*'
  def __init__(self,regular_dirpath):
    high_dirpath = os.path.split(regular_dirpath)[0]
    t1_filepath_list = glob.glob(regular_dirpath + os.sep + self.star + os.sep + self.t1_str + os.sep + self.star)
    bold_filepath_list = glob.glob(regular_dirpath + os.sep + self.star + os.sep + self.bold_str + os.sep + self.star)
    for item in t1_filepath_list + bold_filepath_list:
      output_dirpath = high_dirpath + os.sep + self.dpabi_str + self.split2(item) + os.sep + self.split3(item)
      print('item:',item)
      if not os.path.exists(output_dirpath):
        os.makedirs(output_dirpath)
      shutil.copy2(item,output_dirpath)
      
  @staticmethod
  def split1(path):
    return os.path.split(path)[1]
     
  @staticmethod
  def split2(path):
    return os.path.split(os.path.split(path)[0])[1]
  
  @staticmethod
  def split3(path):
    return os.path.split(os.path.split(os.path.split(path)[0])[0])[1]  